home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / WFC010.ZIP / SRC / DRAWOBJ.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  9.5 KB  |  463 lines

  1. #include <wfc.h>
  2. #pragma hdrstop
  3.  
  4. /*
  5. ** Author: Samuel R. Blackburn
  6. ** CI$: 76300,326
  7. ** Internet: sammy@sed.csc.com
  8. **
  9. ** You can use it any way you like as long as you don't try to sell it.
  10. **
  11. ** Any attempt to sell WFC in source code form must have the permission
  12. ** of the original author. You can produce commercial executables with
  13. ** WFC but you can't sell WFC.
  14. **
  15. ** Copyright, 1995, Samuel R. Blackburn
  16. **
  17. ** $Workfile: $
  18. ** $Revision: $
  19. ** $Modtime: $
  20. */
  21.  
  22. #if defined( _DEBUG )
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. IMPLEMENT_SERIAL( CRectangle,        CObject,    1 )
  28. IMPLEMENT_SERIAL( CRoundedRectangle, CRectangle, 1 )
  29. IMPLEMENT_SERIAL( CSquare,           CRectangle, 1 )
  30. IMPLEMENT_SERIAL( CEllipse,          CRectangle, 1 )
  31. IMPLEMENT_SERIAL( CCircle,           CSquare,    1 )
  32.  
  33. #if defined( _DEBUG )
  34. #define new DEBUG_NEW
  35. #endif
  36.  
  37. /*
  38. ** A Rectangle drawing object
  39. */
  40.  
  41. CRectangle::CRectangle()
  42. {
  43.    m_Initialize();
  44. }
  45.  
  46. CRectangle::CRectangle( DWORD height, DWORD width, const CPoint& location, COLORREF fill_color, COLORREF line_color )
  47. {
  48.    m_Initialize();
  49.  
  50.    SetHeight( height );
  51.    SetWidth( width );
  52.    SetLocation( location );
  53.    SetFillColor( fill_color );
  54.    SetLineColor( line_color );
  55. }
  56.  
  57. CRectangle::~CRectangle()
  58. {
  59.    SetLocation( CPoint( 0, 0 ) );
  60. }
  61.  
  62. void CRectangle::Copy( const CRectangle& source )
  63. {
  64.    Copy( &source );
  65. }
  66.  
  67. void CRectangle::Copy( const CRectangle * source_p )
  68. {
  69.    m_Height        = source_p->m_Height;
  70.    m_Width         = source_p->m_Width;
  71.    m_LineColor     = source_p->m_LineColor;
  72.    m_FillColor     = source_p->m_FillColor;
  73.    m_Location      = source_p->m_Location;
  74.    m_LineRectangle = source_p->m_LineRectangle;
  75.    m_FillRectangle = source_p->m_FillRectangle;
  76. }
  77.  
  78. void CRectangle::Draw( CDC& device_context )
  79. {
  80.    device_context.FrameRect( m_LineRectangle, &CBrush( m_LineColor ) );
  81.    device_context.FillRect(  m_FillRectangle, &CBrush( m_FillColor ) );
  82. }
  83.  
  84. #if defined( _DEBUG )
  85.  
  86. void CRectangle::Dump( CDumpContext& dump_context ) const
  87. {
  88.    CObject::Dump( dump_context );
  89.  
  90.    dump_context << "m_Height = "        << m_Height        << "\n";
  91.    dump_context << "m_Width = "         << m_Width         << "\n";
  92.    dump_context << "m_LineColor = RGB( " << GetRValue( m_LineColor ) << ", " << GetGValue( m_LineColor ) << ", " << GetBValue( m_LineColor ) << " )\n";
  93.    dump_context << "m_FillColor = RGB( " << GetRValue( m_FillColor ) << ", " << GetGValue( m_FillColor ) << ", " << GetBValue( m_FillColor ) << " )\n";
  94.    dump_context << "m_Location = "      << m_Location      << "\n";
  95.    dump_context << "m_LineRectangle = " << m_LineRectangle << "\n";
  96.    dump_context << "m_FillRectangle = " << m_FillRectangle << "\n";
  97. }
  98.  
  99. #endif // _DEBUG
  100.  
  101. COLORREF CRectangle::GetFillColor( void ) const
  102. {
  103.    return( m_FillColor );
  104. }
  105.  
  106. DWORD CRectangle::GetHeight( void ) const
  107. {
  108.    return( m_Height );
  109. }
  110.  
  111. COLORREF CRectangle::GetLineColor( void ) const
  112. {
  113.    return( m_LineColor );
  114. }
  115.  
  116. void CRectangle::GetRectangle( CRect& destination ) const
  117. {
  118.    destination = m_LineRectangle;
  119. }
  120.  
  121. DWORD CRectangle::GetWidth( void ) const
  122. {
  123.    return( m_Width );
  124. }
  125.  
  126. void CRectangle::m_Initialize( void )
  127. {
  128.    m_Location.x = 0;
  129.    m_Location.y = 0;
  130.    m_LineRectangle.SetRectEmpty();
  131.    m_FillRectangle.SetRectEmpty();
  132.    SetFillColor( WHITE );
  133.    SetLineColor( BLACK );
  134. }
  135.  
  136. void CRectangle::m_SetRectangles( void )
  137. {
  138.    m_LineRectangle = CRect( m_Location.x, m_Location.y, m_Location.x + m_Width, m_Location.y + m_Height );
  139.    m_FillRectangle = m_LineRectangle;
  140.    m_FillRectangle.InflateRect( -1, -1 );
  141. }
  142.  
  143. void CRectangle::OnClick( void )
  144. {
  145.    return;
  146. }
  147.  
  148. void CRectangle::Serialize( CArchive& archive )
  149. {
  150.    CObject::Serialize( archive );
  151.  
  152.    if ( archive.IsStoring() )
  153.    {
  154.       archive << m_Height;
  155.       archive << m_Width;
  156.       archive << m_LineColor;
  157.       archive << m_FillColor;
  158.       archive << m_Location;
  159.    }
  160.    else
  161.    {
  162.       archive >> m_Height;
  163.       archive >> m_Width;
  164.       archive >> m_LineColor;
  165.       archive >> m_FillColor;
  166.       archive >> m_Location;
  167.  
  168.       SetHeight( m_Height );
  169.       SetWidth( m_Width );
  170.       SetLineColor( m_LineColor );
  171.       SetFillColor( m_FillColor );
  172.       SetLocation( m_Location );
  173.    }
  174. }
  175.  
  176. void CRectangle::SetFillColor( COLORREF color )
  177. {
  178.    m_FillColor = color;
  179. }
  180.  
  181. void CRectangle::SetHeight( DWORD height )
  182. {
  183.    m_Height = height;
  184.    m_SetRectangles();
  185. }
  186.  
  187. void CRectangle::SetLineColor( COLORREF color )
  188. {
  189.    m_LineColor = color;
  190. }
  191.  
  192. void CRectangle::SetLocation( const CPoint& source )
  193. {
  194.    m_Location = source;
  195.    m_SetRectangles();
  196. }
  197.  
  198. void CRectangle::SetSize( const CSize& size )
  199. {
  200.    SetWidth(  size.cx );
  201.    SetHeight( size.cy );
  202.    m_SetRectangles();
  203. }
  204.  
  205. void CRectangle::SetWidth( DWORD width )
  206. {
  207.    m_Width = width;
  208.    m_SetRectangles();
  209. }
  210.  
  211. /*
  212. ** Rounded Rectangle object
  213. */
  214.  
  215. CRoundedRectangle::CRoundedRectangle()
  216. {
  217. }
  218.  
  219. CRoundedRectangle::~CRoundedRectangle()
  220. {
  221. }
  222.  
  223. void CRoundedRectangle::Copy( const CRoundedRectangle& source )
  224. {
  225.    Copy( &source );
  226. }
  227.  
  228. void CRoundedRectangle::Copy( const CRoundedRectangle * source_p )
  229. {
  230.    CRectangle::Copy( source_p );
  231.  
  232.    m_RoundingPoint = source_p->m_RoundingPoint;
  233. }
  234.  
  235. void CRoundedRectangle::Draw( CDC& device_context )
  236. {
  237.    device_context.RoundRect( &m_LineRectangle, m_RoundingPoint );
  238. }
  239.  
  240. #if defined( _DEBUG )
  241.  
  242. void CRoundedRectangle::Dump( CDumpContext& dump_context ) const
  243. {
  244.    CRectangle::Dump( dump_context );
  245.  
  246.    dump_context << "m_RoundingPoint = " << m_RoundingPoint << "\n";
  247. }
  248.  
  249. #endif // _DEBUG
  250.  
  251. DWORD CRoundedRectangle::GetRoundingSize( void ) const
  252. {
  253.    return( m_RoundingPoint.x );
  254. }
  255.  
  256. void CRoundedRectangle::Serialize( CArchive& archive )
  257. {
  258.    CRectangle::Serialize( archive );
  259.  
  260.    if ( archive.IsStoring() )
  261.    {
  262.       archive << m_RoundingPoint.x;
  263.    }
  264.    else
  265.    {
  266.       archive >> m_RoundingPoint.x;
  267.  
  268.       SetRoundingSize( m_RoundingPoint.x );
  269.    }
  270. }
  271.  
  272. void CRoundedRectangle::SetRoundingSize( DWORD rounding_size )
  273. {
  274.    m_RoundingPoint.x = rounding_size;
  275.    m_RoundingPoint.y = rounding_size;
  276. }
  277.  
  278. /*
  279. ** A Square object
  280. */
  281.  
  282. CSquare::CSquare()
  283. {
  284.    m_Initialize();
  285.  
  286.    SetHeight( 10 );
  287. }
  288.  
  289. CSquare::CSquare( DWORD size, const CPoint& location, COLORREF fill_color, COLORREF line_color )
  290. {
  291.    m_Initialize();
  292.  
  293.    SetHeight( size );
  294.    SetLocation( location );
  295.    SetFillColor( fill_color );
  296.    SetLineColor( line_color );
  297. }
  298.  
  299. CSquare::~CSquare()
  300. {
  301.    SetLocation( CPoint( 0, 0 ) );
  302. }
  303.  
  304. #if defined( _DEBUG )
  305.  
  306. void CSquare::Dump( CDumpContext& dump_context ) const
  307. {
  308.    CRectangle::Dump( dump_context );
  309. }
  310.  
  311. #endif // _DEBUG
  312.  
  313. void CSquare::Serialize( CArchive& archive )
  314. {
  315.    CRectangle::Serialize( archive );
  316. }
  317.  
  318. void CSquare::SetHeight( DWORD height )
  319. {
  320.    m_Height = height;
  321.    m_Width  = height;
  322.    m_SetRectangles();
  323. }
  324.  
  325. void CSquare::SetSize( const CSize& size )
  326. {
  327.    m_Height = size.cx;
  328.    m_Width  = size.cx;
  329.    m_SetRectangles();
  330. }
  331.  
  332. void CSquare::SetWidth( DWORD width )
  333. {
  334.    m_Width  = width;
  335.    m_Height = width;
  336.    m_SetRectangles();
  337. }
  338.  
  339. /*
  340. ** An ellipse...
  341. */
  342.  
  343. CEllipse::CEllipse()
  344. {
  345.    m_Initialize();
  346. }
  347.  
  348. CEllipse::CEllipse( DWORD height, DWORD width, const CPoint& location, COLORREF fill_color, COLORREF line_color )
  349. {
  350.    m_Initialize();
  351.  
  352.    SetHeight( height );
  353.    SetWidth( width );
  354.    SetLocation( location );
  355.    SetFillColor( fill_color );
  356.    SetLineColor( line_color );
  357. }
  358.  
  359. CEllipse::~CEllipse()
  360. {
  361.    SetLocation( CPoint( 0, 0 ) );
  362. }
  363.  
  364. void CEllipse::Draw( CDC& device_context )
  365. {
  366.    CPen line_pen( PS_SOLID, 1, m_LineColor );
  367.  
  368.    CBrush fill_brush( m_FillColor );
  369.  
  370.    CPen   *old_pen   = device_context.SelectObject( &line_pen );
  371.    CBrush *old_brush = device_context.SelectObject( &fill_brush );
  372.  
  373.    device_context.Ellipse( m_LineRectangle );
  374.  
  375.    device_context.SelectObject( old_brush );
  376.    device_context.SelectObject( old_pen );
  377.  
  378.    fill_brush.DeleteObject();
  379.    line_pen.DeleteObject();
  380. }
  381.  
  382. #if defined( _DEBUG )
  383.  
  384. void CEllipse::Dump( CDumpContext& dump_context ) const
  385. {
  386.    CRectangle::Dump( dump_context );
  387. }
  388.  
  389. #endif // _DEBUG
  390.  
  391. void CEllipse::Serialize( CArchive& archive )
  392. {
  393.    CRectangle::Serialize( archive );
  394.  
  395.    if ( archive.IsStoring() != TRUE )
  396.    {
  397.       SetLineColor( m_LineColor );
  398.    }
  399. }
  400.  
  401. /*
  402. ** A Circle
  403. */
  404.  
  405. CCircle::CCircle()
  406. {
  407.    m_Initialize();
  408.  
  409.    SetHeight( 10 );
  410. }
  411.  
  412. CCircle::CCircle( DWORD size, const CPoint& location, COLORREF fill_color, COLORREF line_color )
  413. {
  414.    m_Initialize();
  415.  
  416.    SetHeight( size );
  417.    SetLocation( location );
  418.    SetFillColor( fill_color );
  419.    SetLineColor( line_color );
  420. }
  421.  
  422. CCircle::~CCircle()
  423. {
  424.    SetLocation( CPoint( 0, 0 ) );
  425. }
  426.  
  427. void CCircle::Draw( CDC& device_context )
  428. {
  429.    CPen line_pen( PS_SOLID, 1, m_LineColor );
  430.  
  431.    CBrush fill_brush( m_FillColor );
  432.  
  433.    CPen   *old_pen   = device_context.SelectObject( &line_pen   );
  434.    CBrush *old_brush = device_context.SelectObject( &fill_brush );
  435.  
  436.    device_context.Ellipse( m_LineRectangle );
  437.  
  438.    device_context.SelectObject( old_brush );
  439.    device_context.SelectObject( old_pen );
  440.  
  441.    fill_brush.DeleteObject();
  442.    line_pen.DeleteObject();
  443. }
  444.  
  445. #if defined( _DEBUG )
  446.  
  447. void CCircle::Dump( CDumpContext& dump_context ) const
  448. {
  449.    CSquare::Dump( dump_context );
  450. }
  451.  
  452. #endif // _DEBUG
  453.  
  454. void CCircle::Serialize( CArchive& archive )
  455. {
  456.    CSquare::Serialize( archive );
  457.  
  458.    if ( archive.IsStoring() != TRUE )
  459.    {
  460.       SetLineColor( m_LineColor );
  461.    }
  462. }
  463.